#!/usr/bin/env node

const inquirer = require('inquirer')
const path = require('path')
const fs = require('fs')
const ejs = require('ejs')

inquirer.prompt([
   {
      type: 'input',
      name: 'name',
      message: 'Project Name',
      default: 'ldzProject'
   },
   {
      type: 'input',
      name: 'version',
      message: 'Project version',
      default: '0.0.1'
   }
]).then(answer => {
   const tempDir = path.join(__dirname, 'templates')
   const destDir = process.cwd()
   fs.readdir(tempDir, (err, files) => {
      if (err) throw err
      files.forEach(file => {
         ejs.renderFile(path.join(tempDir, file), answer, (err, result) => {
            if (err) throw err
            fs.writeFileSync(path.join(destDir, file), result)
         })
      })
   })
})
